<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class admin_commnet extends Controller
{
    //加载视图层 评论首页
    public function index()
    {
        //查数据库
        $result = DB::select("select `id`,`dc_id`,`dc_pid`,`dc_time`,`dc_dz` from `dycomment`");
        foreach ($result as $v){
            $uid = $v->dc_pid;
            $list[] = DB::select("select `u_name` from `user` WHERE id=".$uid);
            foreach ($list as $a){
                foreach ($a as $p){
                    foreach ($p as $q){
                        $v->name = $q;
                    }
                }
            }
        }
        return view('admin.admin_comment', ['result' => $result]);
    }

    //删除评论字段
    public function del(Request $request, $id)
    {
        //获取传来的数据
        $id = $id;
        // 删除数据
        $result = DB::delete("delete from dycomment where id=?", [$id]);

        //判断如果删除成功返回列表页
        if ($request) {
            return redirect('/comment');
        }
    }
}
